﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Net;

using System.ServiceModel;
using System.ServiceModel.Description;

using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Discovery;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Client;
using Microsoft.Xrm.Client.Services;
using Microsoft.Xrm.Client.Configuration;
using Microsoft.Xrm.Portal;
using Microsoft.Xrm;

using Microsoft.Crm.Sdk.Messages;
using Microsoft.Crm.Services.Utility;

namespace CRM2ORCH
{
    public class Connection
    {
        public Guid contactId;
        //Organization URL
        public Uri OrganizationUri;
        public ClientCredentials creds;
        public OrganizationService service;
        public string message = string.Empty;
        public OrganizationService setConnection()
        {
            try
            {
                string userName = System.Configuration.ConfigurationManager.AppSettings["username"];
                string password = System.Configuration.ConfigurationManager.AppSettings["password"];
                string url = System.Configuration.ConfigurationManager.AppSettings["url"];

                contactId = Guid.Empty;
                //CrmConnection crmConnection = CrmConnection.Parse("Url=https://microsoftitsm.api.crm.dynamics.com/; Username=DPasqualicchio@MicrosoftITSM.com; Password=M1cr0s0ft;");
                CrmConnection crmConnection = CrmConnection.Parse("Url="+url+"; Username="+userName+"; Password="+password+";");
                service = new OrganizationService(crmConnection);
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return service;
        }

    }
}